//
//  TestPerson.m
//  iOSCodeLearning
//
//  Created by TFAppleWork-Summer on 2018/3/29.
//  Copyright © 2018年 Ace. All rights reserved.
//

#import "TestPerson.h"

@implementation TestPerson
// 模仿UIApplication 写一个单例
static TestPerson *_instance;
// 1 程序一运行就创建对象
// 当类被加载到内存当中就会调用
+(void)load{
    NSLog(@"%s",__func__);
   _instance= [[TestPerson alloc] init];
}

//2 创建的对象只有一个

+(instancetype)sharePerson{
    return _instance;
}

//3 只要调用alloc程序就崩溃
/* *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '只能有一个person'***
*/
+(instancetype)alloc{
    if (_instance) {
        // 程序崩溃
        NSException *exc = [NSException exceptionWithName:@"NSInternalInconsistencyException"
                                                   reason:@"只能有一个person"
                                                 userInfo:nil];
        [exc raise];
    }
        return [super alloc];
    
}


@end
